//
//  YAYIWaitPayCell.m
//  YAYIDoctor
//
//  Created by hxp on 16/5/5.
//  Copyright © 2016年 hxp. All rights reserved.
//

#import "YAYIRefundUnfinishedCell.h"

@interface YAYIRefundUnfinishedCell()

@property (nonatomic,strong)UILabel *date;
@property (nonatomic,strong)UILabel *time;
@property (nonatomic,strong)UILabel *patient;
@property (nonatomic,strong)UILabel *phone;
@property (nonatomic,strong)UILabel *hospital;
@property (nonatomic,strong)UILabel *money;
@property (nonatomic,strong)UILabel *status;
@property (nonatomic,strong)UILabel *seprateLine;

@property (nonatomic,strong)UIView *background;

@end

@implementation YAYIRefundUnfinishedCell


-(void)setModel:(YAYINoPayOrderModel *)model
{
    _model = model;
    
    self.date.text = [NSString  dateString:_model.createtime];
    self.time.attributedText =  [NSString content:@"时间" name:[NSString  timeString:_model.createtime]];
    self.patient.attributedText = [NSString content:@"就诊人" name:_model.patientname];
    self.phone.attributedText = [NSString content:@"联系电话" name:_model.patientMobile];
    self.hospital.text = _model.hospitalname;
    
    CGFloat price = ([self.model.totalprice floatValue] -  [self.model.reduce floatValue] ) / 100.0;
    self.money.attributedText = [NSString content:@"费用" name:[NSString stringWithFormat:@"¥ %.2f", price]];
    
    self.status.text = (model.refundstate.integerValue == 0) ? @"退款中" : @"已退款";
}


+ (instancetype)cellWith:(UITableView *)tablevie
{
    static NSString *cellID = @"refundUnfinishedCell";
    
    YAYIRefundUnfinishedCell *cell = [tablevie dequeueReusableCellWithIdentifier:cellID];
    
    if (nil == cell) {
        cell = [[YAYIRefundUnfinishedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        
    }
    return cell;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubView];
    }
    return self;
}


-(void)setupSubView{
    
    self.date = [UILabel new];
    self.date.clipsToBounds = YES;
    self.date.layer.cornerRadius = 10;
    self.date.textAlignment = NSTextAlignmentCenter;
    self.date.textColor = [UIColor whiteColor];
    self.date.font = [UIFont systemFontOfSize:font13 ];
    self.date.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2];
    [self.contentView addSubview:self.date];
    
    self.background = [UIView new];
    self.background.backgroundColor = [UIColor whiteColor];
    self.background.clipsToBounds = YES;
    self.background.layer.cornerRadius =5;
    [self.contentView addSubview:self.background];
    self.time = [UILabel new];
    self.time.font = [UIFont systemFontOfSize:font15];
    self.time.textColor = [UIColor lightGrayColor];
    [self.background addSubview:self.time];
    self.patient = [UILabel new];
    self.patient.font = [UIFont systemFontOfSize:font15];
    self.patient.textColor = [UIColor lightGrayColor];
    [self.background addSubview:self.patient];
    self.phone = [UILabel new];
    self.phone.font = [UIFont systemFontOfSize:font15];
    self.phone.textColor = [UIColor lightGrayColor];
    [self.background addSubview:self.phone];
    self.hospital = [UILabel new];
    self.hospital.textColor = [UIColor lightGrayColor];
    self.hospital.font = [UIFont systemFontOfSize:font15];
    [self.background addSubview:self.hospital];
    
    self.money = [UILabel new];
    self.money.font = [UIFont systemFontOfSize:font15];
    self.money.textColor = [UIColor lightGrayColor];
    [self.background addSubview:self.money];
    
    self.status = [UILabel new];
    self.status.font = [UIFont systemFontOfSize:font15];
    self.status.textColor = [UIColor lightGrayColor];
    [self.background addSubview:self.status];
    
    self.seprateLine = [UILabel new];
    self.seprateLine.backgroundColor = YAYIColor(0xdd, 0xdd, 0xdd);
    [self.background addSubview:self.seprateLine];
    
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.titleLabel.font = [UIFont systemFontOfSize:font16];
    
    [self.button setTitle:@"退款" forState:UIControlStateNormal];
    [self.button setImage:[UIImage imageNamed:@"moneyIcon"] forState:UIControlStateNormal];
    [self.button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    self.button.layer.borderColor = [UIColor redColor].CGColor;
    self.button.imageEdgeInsets = UIEdgeInsetsMake(0, -3, 0, 3);
    self.button.titleEdgeInsets = UIEdgeInsetsMake(0, 3, 0, -3);
    
    self.button.layer.borderWidth = 1;
    self.button.layer.borderColor = [UIColor redColor].CGColor;
    self.button.clipsToBounds = YES;
    self.button.layer.cornerRadius = 3;
    [self.background addSubview:self.button];
    
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    [self.date mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(100, 18));
        make.top.equalTo(@(14));
    }];
    
    [self.background mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.date.mas_bottom).with.offset(20);
        make.left.equalTo(@(8));
        make.right.equalTo(@(-8));
        make.height.equalTo(@(189));
    }];
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.background.mas_left).with.offset(20);
        make.top.mas_equalTo(self.background.mas_top).with.offset(25);
        make.size.mas_equalTo(CGSizeMake(120, 20));
    }];
    [self.patient mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.time.mas_bottom).with.offset(6);
        make.left.mas_equalTo(self.time.mas_left);
        make.size.mas_equalTo(CGSizeMake(180, 20));
    }];
    [self.phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.time.mas_left);
        make.top.mas_equalTo(self.patient.mas_bottom).with.offset(6);
        make.size.mas_equalTo(CGSizeMake(220, 20));
    }];
    [self.hospital mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.time.mas_left);
        make.top.mas_equalTo(self.phone.mas_bottom).with.offset(6);
        make.size.mas_equalTo(CGSizeMake(220, 20));
    }];
    [self.money mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.background.mas_right).with.offset(-10);
        make.top.mas_equalTo(self.time.mas_top);
        make.size.mas_equalTo(CGSizeMake(120, 20));
    }];
    [self.status mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.money.mas_right);
        make.top.mas_equalTo(self.hospital.mas_top);
        make.size.mas_equalTo(CGSizeMake(60, 20));
    }];
    [self.seprateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.hospital.mas_bottom).with.offset(14);
        make.left.equalTo(self.time.mas_left);
        make.right.mas_equalTo(self.money.mas_right);
        make.height.mas_equalTo(0.5);
    }];
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.seprateLine.mas_bottom).with.offset(10);
        make.centerX.mas_equalTo(self.background.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(133, 30));
    }];
     
}
@end
